package Chapter6.dao;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.HibernateException;

import Chapter6.one_to_many.Book;
import Chapter6.one_to_many.Publisher;

import learnning.dao.base.HibernateDao;

public class BookDao extends HibernateDao {
	public void add(String nameBook, String namePub) {
		try {
			begin();
			Book book = new Book(nameBook);
			Publisher publisher = new Publisher(namePub);
			book.setPublisher(publisher);
			Set<Book> books = new HashSet<Book>();
			books.add(book);
			publisher.setBooks(books);
			getSession().save(publisher);
			getSession().save(book);
			commit();
		} catch (HibernateException e) {
			rollback();
			e.printStackTrace();
		}
	}
}
